Questions
49 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
49 / 50

How can you style the first letter of only the first paragraph using pseudo-classes?

Styling the First Letter of the First Paragraph in CSS

You can target the first letter of only the first paragraph using the :first-child pseudo-class in combination with the ::first-letter pseudo-element. This allows you to apply special styles to the initial letter of the first paragraph without affecting other paragraphs.

Key Points
  1. 1

    :first-child selects the first element among its siblings.

  2. 2

    ::first-letter targets only the first letter of an element.

  3. 3

    Combining them lets you style the first letter of the first paragraph specifically.

Example: Style First Letter of First Paragraph

In this example, only the first letter of the first paragraph is enlarged and colored blue. Subsequent paragraphs remain unaffected.

Best Practices
  1. 1

    Use ::first-letter for decorative purposes or to emphasize the start of content.

  2. 2

    Combine with :first-child to avoid styling multiple paragraphs unintentionally.

  3. 3

    Ensure that styling does not compromise readability.

  4. 4

    Test on different screen sizes for consistent appearance.

Difficulty: 3/10
Topics: first-letter pseudo-class, CSS specificity, selector scoping

Scenario Questions

0-2 years experience
  1. 1

    How would you style the first letter of only the first paragraph on a landing page so it’s larger and bold, without affecting any other paragraphs?

  2. 2

    What happens if you apply ::first-letter to a div that contains multiple paragraphs — will it style the first letter of every paragraph or just the first one?

  3. 3

    You wrote a rule for ::first-letter but it’s not working — the paragraph has a span wrapping the first letter. Why might that be?

2-5 years experience
  1. 1

    A designer wants the first letter of the first paragraph in a blog post to be a drop cap, but the CMS sometimes injects a hidden comment before the paragraph — how would you debug and fix this?

  2. 2

    We’re using a CSS framework that resets all ::first-letter styles, and now our drop caps are broken. How would you override this without breaking other components?

  3. 3

    The first paragraph in our article component sometimes starts with a quote mark or emoji — how do you ensure ::first-letter still works correctly in those edge cases?

5-8 years experience
  1. 1

    You’re building a scalable typography system for a global content platform — how would you design a reusable drop cap component that handles RTL languages, mixed scripts, and dynamic content without performance hits?

  2. 2

    In a large-scale CMS, editors can insert arbitrary HTML into article bodies. How do you ensure ::first-letter styling is robust against malformed markup, nested elements, or dynamically injected content without causing layout shifts?

  3. 3

    How would you implement a drop cap that degrades gracefully on low-end devices or when CSS is disabled, while still maintaining semantic HTML and accessibility?

8+ years experience
  1. 1

    We’re migrating a legacy content platform where drop caps were implemented with JS and inline styles — how would you architect a CSS-first solution that ensures backward compatibility, avoids layout thrashing, and supports future theming across 50+ product surfaces?

  2. 2

    How would you coordinate with editorial, design, and accessibility teams to standardize drop cap behavior across global markets, considering typographic conventions in Arabic, Chinese, and Devanagari scripts — and how do you measure success?

  3. 3

    Your team owns the core typography system used by 20+ products. How do you design the API and documentation for ::first-letter-based drop caps to prevent misuse, ensure performance, and allow for future extensibility without breaking existing implementations?

Follow-up Questions

  • What happens if the first paragraph has an inline element like a span before the first letter?
  • How would you handle this if the paragraph is dynamically generated and might not always be the first child?
  • Could this break if the user has custom user-agent styles or a CSS reset applied?